﻿using CommunityToolkit.Maui;
using ContactSMS.Client.ViewModels;
using ContactSMS.Client.Views;
using Microsoft.Extensions.Logging;
using ContactSMS.UseCases.PluginInterfaces;
using ContactSMS.Plugins.DataStore.InMemory;
using ContactSMS.Client.Service;
using ContactSMS.Client.Models;

namespace ContactSMS.Client
{
    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .UseMauiCommunityToolkit()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                    fonts.AddFont("iconfont.ttf", "iconfont");
                });

#if DEBUG
            builder.Logging.AddDebug();
#endif

            builder.Services.AddScoped<IContactRepository, ContactInMemoryRepository>();

            builder.Services.AddScoped<ContactViewModel>();
            builder.Services.AddScoped<CommonSearchViewModel>();
            builder.Services.AddScoped<AddContactViewModel>();
            builder.Services.AddScoped<ContactDetailViewModel>();
            builder.Services.AddScoped<CallRecordsViewModel>();
            builder.Services.AddScoped<MessageViewModel>();
            builder.Services.AddScoped<MessageDetailViewModel>();
            builder.Services.AddScoped<LoginViewModel>();
            builder.Services.AddScoped<MeViewModel>();

            builder.Services.AddScoped<ContactPage>();
            builder.Services.AddScoped<AddContactPage>();
            builder.Services.AddScoped<CallRecordsPage>();
            builder.Services.AddScoped<MessagePage>();
            builder.Services.AddScoped<CommonSearchPage>();
            builder.Services.AddScoped<ContactDetailPage>();
            builder.Services.AddScoped<MessageDetailPage>();
            builder.Services.AddScoped<LoginPage>();
            builder.Services.AddScoped<SignUpPage>();
            builder.Services.AddScoped<MePage>();

            builder.Services.AddScoped<AuthService>();
            builder.Services.AddScoped<LoginService>();
            builder.Services.AddScoped<ContactService>();
            builder.Services.AddScoped<PhoneRecordService>();
            builder.Services.AddScoped<MessageService>();

            builder.Services.AddSingleton<RegisterModel>();
            builder.Services.AddSingleton<AddPhoneModel>();
            builder.Services.AddSingleton<AddContactModel>();

            return builder.Build();
        }
    }
}
